$(document).ready(function() {
    /*========================================按照课程名称来显示班级====================================*/
    $("#courseName").change(function() {
        $.ajax({
            async: false,
            cache: false,
            type: 'post',
            dataType: 'json',
            url: '/Examination/user/selectClasses',
            // 请求的action路径
            data: {
                cocourseCode: $("#courseName").val()
            },
            error: function() { // 请求失败处理函数
                alert("false");
            },
            success: function(data) { // 请求成功处理函数
                $("#classes option").remove();
                for (i = 0; i < data.length; i++) {
                    var name = data[i].cname;
                    var id = data[i].cid;
                    var $option = $("<option/>").val(id).html(name);
                    $option.appendTo($("#classes"));
                }
            }
        });

    });
    /*=======================================显示从后台传过来的课程代码和班级名字===============================*/
    var currentCocourseCode = $("#currentCocourseCode").html();
    var currentCid = $("#currentCid").html();
    $("#courseName").val(currentCocourseCode);
    $("#courseName").change();
    $("#classes").val(currentCid);
    if(currentCocourseCode!=0){
    	$("#submit_answers").removeClass("none");
    	
    }
    else{
    	
    }
    /*=================================按课程选择考试题目======================================*/
    $("#click_btn").click(function(){
    	location="/Examination/user/topicShow/"+$("#courseName").val()+"?currentCid="+$("#classes").val();
    })
    /*==================================提交考试答案=======================================================*/
    $("#submit_answers").click(function(){
    	alert("tijiao ");
    	var radioGroupList=$(".radioGroup");
    	var dataArr=new Array();
    	for(var i=0;i<radioGroupList.length;i++){
    		var value=$(radioGroupList[i]).find("input:checked").val();
    		if(value==undefined){
    			$(".radioGroup:eq(i)").css("background-color","F00");
    			return;
    		}
    		dataArr.push(value);
    	}
       alert(dataArr.length);
    	 $.ajax({
             async: false,
             cache: false,
             type: 'post',
             dataType: 'json',
             url: "/Examination/user/submitAnswer",
             // 请求的action路径
             data: {
            	 courseId : $("#currentCocourseCode").html(),
            	 classId : $("#currentCid").html(),
            	 ansIndexList:dataArr
             },
             error: function() { // 请求失败处理函数
                 alert("false");
             },
             success: function(data) { // 请求成功处理函数
            	 var result = confirm('你的成绩是'+data+'是否查看错误题目');  
            	    if(result){  
            	        location.href="/Examination/user/WrongTitlePage?courseId="+$("#currentCocourseCode").html();
            	    }else{  
            	    	 location.href="/Examination/user/QueryResults"; 
            	    }  
             }
         });
    });
   
});